<?php
/**
 * @version     1.0.0
 * @package     com_school
 * @copyright   Copyright (C) 2013. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 * @author      Chuyen Trung Tran <chuyentt@gmail.com> - http://www.igeotrans.com
 */

// no direct access
defined('_JEXEC') or die;

//Load admin language file
$lang = JFactory::getLanguage();
$lang->load('com_school', JPATH_ADMINISTRATOR);
?>
<?php if( $this->item ) : ?>

    <div class="item_fields">
        
        <ul class="fields_list">

			<li><?php echo JText::_('COM_SCHOOL_FORM_LBL_STUDENT_ID'); ?>:
			<?php echo $this->item->id; ?></li>
			<li><?php echo JText::_('COM_SCHOOL_FORM_LBL_STUDENT_ORDERING'); ?>:
			<?php echo $this->item->ordering; ?></li>
			<li><?php echo JText::_('COM_SCHOOL_FORM_LBL_STUDENT_STATE'); ?>:
			<?php echo $this->item->state; ?></li>
			<li><?php echo JText::_('COM_SCHOOL_FORM_LBL_STUDENT_CHECKED_OUT'); ?>:
			<?php echo $this->item->checked_out; ?></li>
			<li><?php echo JText::_('COM_SCHOOL_FORM_LBL_STUDENT_CHECKED_OUT_TIME'); ?>:
			<?php echo $this->item->checked_out_time; ?></li>
			<li><?php echo JText::_('COM_SCHOOL_FORM_LBL_STUDENT_CREATED_BY'); ?>:
			<?php echo $this->item->created_by; ?></li>
			<li><?php echo JText::_('COM_SCHOOL_FORM_LBL_STUDENT_NAME'); ?>:
			<?php echo $this->item->name; ?></li>
			<li><?php echo JText::_('COM_SCHOOL_FORM_LBL_STUDENT_POINT'); ?>:
			<?php echo $this->item->point; ?></li>
			<li><?php echo JText::_('COM_SCHOOL_FORM_LBL_STUDENT_COURSE_ID'); ?>:
			<?php
				if($this->item->course_id != ''):
					$array = array();
					foreach((array)$this->item->course_id as $value): 
						if(!is_array($value)):
							$array[] = $value;
						endif;
					endforeach;
					$data = array();
					foreach($array as $value):
						$db = JFactory::getDbo();
						$query	= $db->getQuery(true);
						$query
							->select('name')
							->from('`#__school_course`')
							->where('id = ' .$value);
						$db->setQuery($query);
						$results = $db->loadObjectList();
						if($results){
							$data[] = $results[0]->name;
						}
					endforeach;
					$this->item->course_id = implode(',',$data);
				endif; ?>			<?php echo $this->item->course_id; ?></li>


        </ul>
        
    </div>
    <?php if(JFactory::getUser()->authorise('core.edit.own', 'com_school')): ?>
		<a href="<?php echo JRoute::_('index.php?option=com_school&task=student.edit&id='.$this->item->id); ?>">Edit</a>
	<?php endif; ?>
								<?php if(JFactory::getUser()->authorise('core.delete','com_school')):
								?>
									<a href="javascript:document.getElementById('form-student-delete-<?php echo $this->item->id ?>').submit()">Delete</a>
									<form id="form-student-delete-<?php echo $this->item->id; ?>" style="display:inline" action="<?php echo JRoute::_('index.php?option=com_school&task=student.remove'); ?>" method="post" class="form-validate" enctype="multipart/form-data">
										<input type="hidden" name="jform[id]" value="<?php echo $this->item->id; ?>" />
										<input type="hidden" name="jform[ordering]" value="<?php echo $this->item->ordering; ?>" />
										<input type="hidden" name="jform[state]" value="<?php echo $this->item->state; ?>" />
										<input type="hidden" name="jform[checked_out]" value="<?php echo $this->item->checked_out; ?>" />
										<input type="hidden" name="jform[checked_out_time]" value="<?php echo $this->item->checked_out_time; ?>" />
										<input type="hidden" name="jform[created_by]" value="<?php echo $this->item->created_by; ?>" />
										<input type="hidden" name="jform[name]" value="<?php echo $this->item->name; ?>" />
										<input type="hidden" name="jform[point]" value="<?php echo $this->item->point; ?>" />
										<input type="hidden" name="jform[course_id]" value="<?php echo $this->item->course_id; ?>" />
										<input type="hidden" name="option" value="com_school" />
										<input type="hidden" name="task" value="student.remove" />
										<?php echo JHtml::_('form.token'); ?>
									</form>
								<?php
								endif;
							?>
<?php else: ?>
    Could not load the item
<?php endif; ?>
